package com.moon.mybatisplus.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moon.mybatisplus.entity.Dog;
import com.moon.mybatisplus.mapper.master.MasterDogMapper;
import com.moon.mybatisplus.mapper.slave.SlavaDogMapper;
import com.moon.mybatisplus.service.DogService;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * @author ：xxx
 * @description：TODO
 * @date ：2023/12/14 15:35
 */
@Service
public class DogServiceImpl extends ServiceImpl<MasterDogMapper, Dog> implements DogService {

    @Autowired
    @Qualifier("masterSqlSessionTemplate")
    private SqlSessionTemplate masterSqlSessionTemplate;

    @Autowired
    @Qualifier("slaveSqlSessionTemplate")
    private SqlSessionTemplate slaveSqlSessionTemplate;


    public void getDogs() {
        MasterDogMapper masterMapper = masterSqlSessionTemplate.getMapper(MasterDogMapper.class);
        SlavaDogMapper slaveMapper = slaveSqlSessionTemplate.getMapper(SlavaDogMapper.class);
        // 使用mapper进行数据库操作


        Page<Dog> masterDogPage = masterMapper.selectPage(new Page<>(), null);
        Page<Dog> slaveDogPage = slaveMapper.selectPage(new Page<>(), null);

        System.out.println(masterDogPage);
        System.out.println(slaveDogPage);

    }

}
